﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.InterfaceService;
using MDT.LifeSewagePlatform.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace MDT.LifeSewagePlatform.ServiceInstance.Controllers
{
    /// <summary>
    /// 公司
    /// </summary>
    [Route("api/company")]
    [ApiController]
    [Authorize]
    public class CompanyController : BaseController
    {
        [Autowired]

        private  ICompanyService _companyService { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public CompanyController()
        {
        }
        /// <summary>
        /// 添加公司
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> AddCompany([FromForm]AddCompany entity)
        {
            return await _companyService.Add(entity, GetUserID());
           
        }

        /// <summary>
        /// 获取公司
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> GetCompany([FromQuery]CompanyParameter Params)
        {
             return await _companyService.GetCompanys(Params);
        }

        /// <summary>
        /// 获取公司
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("key")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> GetCompanyList([FromQuery] CompanyParameter Params)
        {
            return await _companyService.GetCompanyList(Params);
        }

        /// <summary>
        /// 更新公司
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>

        [HttpPut]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> Update([FromForm] UpdateCompany Params)
        {
            return await _companyService.Update(Params, GetUserID());
            
        }
        /// <summary>
        /// 删除公司
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> Delete(int id)
        {
            return await _companyService.Delete(id, GetUserID());
        }
        /// <summary>
        /// 获取city通过公司
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("citys/{id}")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> GetCitysByCompany(int id)
        {
            return  await _companyService.GetCitysByCompany(id);
        }

        /// <summary>
        /// 获取area通过公司
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("areas/{Id}")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> GetAreasByCompany(int Id)
        {
            return await _companyService.GetAreasByCompany(Id);
        }
    }
}
